package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IAboutUsService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.AboutUsCreateValidate;
import com.mdd.admin.validate.AboutUsUpdateValidate;
import com.mdd.admin.validate.AboutUsSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.AboutUsListedVo;
import com.mdd.admin.vo.AboutUsDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/us")
@Api(tags = "关于我们管理")
public class AboutUsController {

    @Resource
    IAboutUsService iAboutUsService;

    @GetMapping("/list")
    @ApiOperation(value="关于我们列表")
    public AjaxResult<PageResult<AboutUsListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated AboutUsSearchValidate searchValidate) {
        PageResult<AboutUsListedVo> list = iAboutUsService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="关于我们详情")
    public AjaxResult<AboutUsDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        AboutUsDetailVo detail = iAboutUsService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "关于我们新增")
    @PostMapping("/add")
    @ApiOperation(value="关于我们新增")
    public AjaxResult<Object> add(@Validated @RequestBody AboutUsCreateValidate createValidate) {
        iAboutUsService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "关于我们编辑")
    @PostMapping("/edit")
    @ApiOperation(value="关于我们编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody AboutUsUpdateValidate updateValidate) {
        iAboutUsService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "关于我们删除")
    @PostMapping("/del")
    @ApiOperation(value="关于我们删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iAboutUsService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
